<template>
	<view class="login">
		<view class="content">
			<!-- 头部logo -->
			<view class="header">
				<image :src="logoImage"></image>
			</view>
			<!-- 主体表单 -->
			<view class="main">
				<wInput v-model="phone" type="text" maxlength="11" placeholder="电话"></wInput>
				<wInput v-model="password" type="password" maxlength="11" placeholder="密码"></wInput>
			</view>
			<wButton class="wbutton" text="登 录" @click="login"></wButton>

			<!-- 微信登陆 -->
			<!-- <view class="other_login cuIcon">
				<view class="login_icon">
					<view class="cuIcon-weixin" @click="login_weixin"></view>
				</view>
			</view> -->

			<!-- 底部信息 -->
			<view class="footer">
				<navigator url="register" open-type="navigate">注册账号</navigator>
			</view>
		</view>
	</view>
</template>

<script>
	let _this;
	import wInput from '../../components/watch-login/watch-input.vue' //input
	import wButton from '../../components/watch-login/watch-button.vue' //button

	export default {
		data() {
			return {
				phone: '17361013318',
				password: '123456',
				key:'',
				//logo图片 base64
				logoImage: '',
				
			};
		},
		components: {
			wInput,
			wButton,
		},
		mounted() {
			_this = this;
			//this.isLogin();

		},
		methods: {
			isLogin() {
				//判断缓存中是否登录过，直接登录
				// try {
				// 	const value = uni.getStorageSync('setUserData');
				// 	if (value) {
				// 		//有登录信息
				// 		console.log("已登录用户：",value);
				// 		_this.$store.dispatch("setUserData",value); //存入状态
				// 		uni.reLaunch({
				// 			url: '../../../pages/index',
				// 		});
				// 	}
				// } catch (e) {
				// 	// error
				// }
			},
			login() {
				//普通登陆
				uni.login({
					provider: 'weixin',
					success: async (loginRes) => {
						const { data: res } = await this.$http({
							url: '/user/onlogin',
							data: {
								code: loginRes.code,
								password: this.password,
								phone: this.phone
							}
						})
						if (res.code != 200) return
						uni.setStorageSync('myInfo', res.data);
						uni.switchTab({
							url: '/pages/activity/activity'
						})
					},
				})
			},/* 
			//微信一键登陆
			login_weixin() {
				//获取sessionKey
				uni.login({
				  provider: 'weixin',
				  success: loginRes=> {
				    const {code}=loginRes
						uni.request({
							url: 'https://api.weixin.qq.com/sns/jscode2session',
							data: {
								appid:'wxee4db3ec9c618898',
								secret:'6710e51ccc8b965fbe2665192459dd81',
								js_code:code,
								grant_type:'authorization_code'
							},
							success: res => {
								this.key=res.data.session_key
							}
						});
				  }
				})
				uni.getUserProfile({
					desc: '微信登陆',
					success: (res) => {
						this.$http({
							url:'/user/getphone',
							method:'post',
							data:{
								encryptedData:res.encryptedData,
								iv:res.iv,
								sessionKey:this.key
							},
							success:res=>{
								console.log(111);
							}
						})
					}
				})
			} */
		}
	}
</script>

<style>
	@import url("../../components/watch-login/css/icon.css");
	@import url("./css/main.css");
</style>
